Built-in Modules > print Function
print Function
Overview
The print
function is a server-side tool used to display values of variables, similar to console.log()
in client-side JavaScript. It also automatically captures all console.log()
, console.error()
, console.warn()
, and console.info()
calls and routes them through print
.
Function Definition
function print(nameOrValue, valueIfNamed)
- If called with one argument, it directly prints the value.
- If called with two arguments, the first is treated as a label and the second as the value.
Usage Examples
// Import not required if print is globally available,
// but supported for compatibility with older versions:
import { print } from "./modules.js";
// Single value
print("Hello world");
// Named value
print("rate", 9.99);
// Captured from console.log
console.log("this is logged");
// Captured with name/value format
console.log("total", 42);
// Also captured:
console.error("something went wrong");
console.warn("careful!");
console.info("loaded");
Output
All values passed to print()
— directly or via console
methods — are stored in an array named print
. This array is automatically included in the logs and test run outputs.:
[
"Hello world",
{ rate: 9.99 },
"this is logged",
{ total: 42 },
"❌ something went wrong",
"⚠️ careful!",
"ℹ️ loaded"
]
Notes
print()
is globally available and automatically hooked into the server logging system.console.log
,console.warn
,console.error
, andconsole.info
are all intercepted and routed throughprint()
.- The older style
import { print } from "./modules.js"
is still supported for backward compatibility.
Summary
The print
function enhances the debugging process in server-side environments by mimicking the behavior of console.log()
while also offering structured logging for inspection. It's designed to work in the JsRates runtime and capture all log output for better visibility during development.